var isRefreshOddsTable = true;
parent.Game13 = new Array();

function NumFormat(intNum){
	if(intNum < 10)return "00" + intNum.toString();
	if(intNum < 100)return "0" + intNum.toString();
	return intNum.toString();
}

function GetWagerTable(){
	if(isRefreshOddsTable == false){
		InsertOdds();
		return;
	}

	var objWTable = document.getElementById("wager_table"), i = 0, intNum = 0, strNum = "", strDisabled = "", StopClass = "";
	var ArrGame = eval("parent.Game"+intBetType);
	var ArrStake = new Array();

	with(objWTable)	{
		while(rows.length > 1)	deleteRow(rows.length - 1);

		for(intNum = 0; intNum <= 99; intNum++)	{
			if(intBetType == 93 && ArrGame.length <= intNum)continue;

			if(i % 5 == 0){
				var intCellNo = 0;
				newTR = insertRow(rows.length);
			}
			newTR.className = "mcen";
			with(newTR){
				strNum = NumFormat(ArrGame[intNum][3]);
										
				newTD = insertCell(intCellNo);
				newTD.className = "mcen_th";
				newTD.innerHTML = strNum;
				intCellNo++;

				newTD = insertCell(intCellNo);
				newTD.className = "mbline_baratio";
				newTD.id = "OddsID"+intNum.toString();
				intCellNo++;
			} //with(newTR)
			i++;
		} //for(intNum = 0; intNum <= 99; intNum++)
	} //with(objWTable)
	isRefreshOddsTable = false;
	InsertOdds();
}

function InsertOdds(){
	var ArrGame = eval("parent.Game"+intBetType);
	var newTD, intNum = 0;
	for(intNum = 0; intNum <= 99; intNum++)	{
		if(intBetType == 93 && ArrGame.length <= intNum)continue;

		newTD = document.getElementById("OddsID"+intNum.toString());
		if(ArrGame[intNum][6] == "1"){
			newTD.className = "mbline_baratio_stop";
		}else{
			newTD.className = "mbline_baratio";
		}

		if(newTD.innerHTML != ""){
			newOdds = document.getElementById("OddsTip1_"+intNum.toString());
			newOdds.innerHTML = ArrGame[intNum][5];
			newOdds.href = "wager_common.php?UserID="+parent.strUserID+"&GambleID="+ArrGame[intNum][1]+"&Bet_Type="+ArrGame[intNum][2]+"&OddsID="+ArrGame[intNum][4]+"&Odds="+ArrGame[intNum][5]+"&LottoID="+ArrGame[intNum][0]+"&Number="+ArrGame[intNum][3]+"&sid="+sid;
		}else{
			newTD.innerHTML = "<a href=\"wager_common.php?UserID="+parent.strUserID+"&GambleID="+ArrGame[intNum][1]+"&Bet_Type="+ArrGame[intNum][2]+"&OddsID="+ArrGame[intNum][4]+"&Odds="+ArrGame[intNum][5]+"&LottoID="+ArrGame[intNum][0]+"&Number="+ArrGame[intNum][3]+"&sid="+sid+"\" class=\"rt_sp_lotto_odds\" target=\"leftFrame\" id=\"OddsTip1_"+intNum.toString()+"\">"+ArrGame[intNum][5]+"</a><input type='checkbox' name='ChoiceNumber["+intNum.toString()+"]' value='"+ArrGame[intNum][3]+"' onclick='ChangeColor(this.checked, "+intNum.toString()+")'>";
		}
	}
}

function ChangeColor(isSelected, intNum){
	var objTD = document.getElementById("OddsID" + intNum.toString());
	if(isSelected){
		objTD.title = objTD.className;
		objTD.style.backgroundColor = "#CCFF99";
	}else{
		objTD.style.backgroundColor = "";
		objTD.className = objTD.title;
	}
}

function InitAction(){
	document.GetOddsForm.submit();
	setIntervalID1 = setInterval("SubmitOddsForm();", 30000);
	setIntervalID2 = setInterval("CountRefresh();", 1000);
}

function SubmitOddsForm(){
	if(isRefresh == false){
		document.GetOddsForm.action = "http://tw.i5.yimg.com/i/tw/hp/spirit/w5.gif";
		document.GetOddsForm.submit();
		window.status = "";
		return;
	}
	document.GetOddsForm.action = "number92_odds.php";
	document.GetOddsForm.submit();
	isRefresh = false;
	intRefreshSec = 0;
}

function CountRefresh(){
	var intGT = 0, intGT2 = 0, strGTm = "", strGTs = "";
	if(intRefreshSec >= RefreshSec)isRefresh = true;
	intGT = parseInt(parent.strGameTime);
	if(intGT < 0)intGT = 0;
	intGT2 = (intGT > 900)?900:intGT;
	strGTm = (Math.floor(intGT2 / 60)).toString();
	if(strGTm.length < 2)strGTm = "0" + strGTm;
	strGTs = (intGT2 % 60).toString();
	if(strGTs.length < 2)strGTs = "0" + strGTs;
	document.getElementById("GameSec").innerHTML = strGTm+":"+strGTs;
	parent.strGameTime = intGT - 1;
	intRefreshSec++;
}

function setTrinNo(strTrinNo){
	document.GetOddsForm.TrinNo.value = strTrinNo;
	isRefreshOddsTable = true;
	parent.Game93 = new Array();
	document.GetOddsForm.submit();
}

function setTrinity(strTrinity){
	document.GetOddsForm.Trinity.value = strTrinity;
	isRefreshOddsTable = true;
	parent.Game93 = new Array();
	document.GetOddsForm.submit();
}

function FinalCheck(){
	var intTotal = 0;
	var ArrGame = eval("parent.Game"+intBetType);
	for(intNum = 0; intNum <= 99; intNum++){
		if(intBetType == 93 && ArrGame.length <= intNum)continue;

		if(document.ShowOddsForm["ChoiceNumber[" + intNum.toString() + "]"].checked)intTotal++;
	}
	if(intTotal == 0)return false
	document.ShowOddsForm.submit();
}

function ResetTable(){
	isRefreshOddsTable = true;
	GetWagerTable();
}